local kanyu = fk.CreateSkill {
  name = "th_kanyu",
  max_phase_use_time = 1,
}

kanyu:addEffect("active", {
  anim_type = "drawcard",
  prompt = "#th_kanyu",
  card_num = 0,
  card_filter = Util.FalseFunc,
  min_target_num = 1,
  target_filter = Util.TrueFunc,
  on_use = function(self, room, effect)
    local player = effect.from
    local tos = effect.tos
    room:sortByAction(tos)
    local method_table = {}
    local player_hands = player:getHandcardNum()
    for _, to in ipairs(tos) do
      if to:getHandcardNum() > player_hands then
        method_table[to] = "discard"
      else
        method_table[to] = "draw"
      end
    end
    for _, to in ipairs(tos) do
      if to:isAlive() then
        if method_table[to] == "discard" and not to:isNude() then
          room:askToDiscard(to, {
            min_num = 1,
            max_num = 1,
            include_equip = true,
            skill_name = kanyu.name,
            cancelable = false
          })
        elseif method_table[to] == "draw" then
          to:drawCards(1, kanyu.name)
        end
      end
    end
    if player.dead then return end
    tos = table.filter(tos, function(t) return t:isAlive() end)
    player_hands = player:getHandcardNum()
    if table.find(tos, function(p) return p:getHandcardNum() == player_hands end) then
      for _, to in ipairs(tos) do
        if not to.chained then
          to:setChainState(true)
        end
      end
    end
  end
}, { check_skill_limit = true })

Fk:loadTranslationTable{
  ["th_kanyu"] = "堪舆",
  [":th_kanyu"] = "出牌阶段限一次，你可以选择任意名角色，其中手牌数大于你的角色弃置一张牌，不大于你的角色摸一张牌，然后若其中有角色手牌数与你相同，横置所有被选择的角色。",

  ["#th_kanyu"] = "堪舆：选择任意名角色弃牌或摸牌，若其中有角色手牌数与你相同，横置所有被选择的角色",
}

return kanyu